<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <title>控制台</title>
    <link rel="stylesheet" href="/lay/layui/css/layui.css">
    <script src="/js/jquery.min.js"></script>
    <script type="text/javascript" src="/lay/layer/layer.js"></script>
    <script src="/lay/layui/layui.js"></script>
    <script type="text/javascript" src="/js/common.js"></script>

</head>
<body class="layui-layout-body">
<div class="create-db-content">
    <form class="layui-form layui-form-pane" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">数据库</label>
            <div class="layui-input-inline">
                <select name="db_name" lay-verify="required" lay-search class="db_list">
                    <option value="">请选择数据库</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div style="margin: 10px 10px 10px 10px;">
                <textarea name="sql" required lay-verify="required" placeholder="在此输入或粘贴您的SQL语句" class="layui-textarea" rows="10" style="font-size: 18px;"></textarea>
            </div>
        </div>
        <div class="layui-form-item" style="margin-left: 10px;">
                <button class="layui-btn" lay-submit lay-filter="formDemo">执行SQL</button>
        </div>
        <div class="layui-form-item">
            <p id="error_tip"></p>
        </div>
    </form>
</div>
</body>
<script>
    $(function () {
        var db_list = sendAjaxRequest('GET', '/database/getAllDatabase', {}, false);
        if (db_list.status == 0) {
            for (var i=0; i< db_list.data.length; i++) {
                var item =db_list.data[i];
                $('.db_list').append('<option value="'+item.Database+'">'+item.Database+'</option>');
            }
        }
    })
    layui.use('form', function(){
        var form = layui.form;
        //监听提交
        form.on('submit(formDemo)', function(data){
            data.field._token = $('meta[name="csrf-token"]').attr('content');
            // layer.msg(JSON.stringify(data.field));
            parent.location.href = '/index/record?db_name='+data.field.db_name+'&sql='+data.field.sql;
            return false;
        });
    });
</script>
</html>